package org.wk.news.controller;

import com.google.gson.JsonObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.wk.core.common.view.PageVo;
import org.wk.core.common.view.ResponseVo;
import org.wk.logger.common.annotation.SysLog;
import org.wk.news.service.NewsManageService;
import org.wk.news.view.NewsClassifiedsVo;
import org.wk.news.view.NewsManageVo;

import java.util.Arrays;
import java.util.Map;

/**
 * @ClassName NewsManageController
 * @Description
 * @Author ZhaoPing'an
 * @Date 2018/6/5 14:13
 */
@RestController
@RequestMapping("/news/manage")
public class NewsManageController {

    @Autowired
    private NewsManageService manageService;

    @SysLog("资讯管理列表")
    @RequestMapping("/list")
    public ResponseVo list(@RequestParam Map<String, Object> params){
        PageVo page = manageService.findNewsManageListPage(params);
        return ResponseVo.success().addAttribute("page", page);
    }

    /**
     * @Description  保存资讯类型
     * @Param [newsType]
     * @author ZhaoPing'an
     * @Date 2018/6/5 11:47
     */
    @SysLog("保存资讯")
    @RequestMapping("/save")
    public ResponseVo save(@RequestBody NewsManageVo manageVo){
        // 保存
        manageService.insert(manageVo);
        return ResponseVo.success();
    }
    /**
     * @Description 获取资讯详情
     * @Param [id]
     * @author ZhaoPing'an
     * @Date 2018/6/8 11:34
     */
    @SysLog("获取资讯详情")
    @RequestMapping("/info/{id}")
    public ResponseVo findNewsInfo(@PathVariable("id")String id){
        NewsManageVo result = manageService.findNewsInfo(id);
        return ResponseVo.success().setData(result);
    }

    /**
     * @Description 修改资讯
     * @Param [newsClassifiedsVo]
     * @author ZhaoPing'an
     * @Date 2018/6/8 11:38
     */
    @SysLog("修改资讯")
    @RequestMapping("/update")
    public ResponseVo update(@RequestBody NewsManageVo newsManageVo){
        // 保存
        manageService.update(newsManageVo);
        return ResponseVo.success();
    }

    /**
     * @Description 删除资讯
     * @Param [ids]
     * @author ZhaoPing'an
     * @Date 2018/6/8 11:40
     */
    @SysLog("删除资讯")
    @RequestMapping("/delete")
    public ResponseVo delete(@RequestBody String[] ids){
        manageService.deleteBatchIds(Arrays.asList(ids));
        return ResponseVo.success();
    }

    /**
     * @Description 发布资讯
     * @Param [newsManageVo]
     * @author ZhaoPing'an
     * @Date 2018/6/13 16:10
     */
    @SysLog("发布资讯")
    @RequestMapping("/publish")
    public ResponseVo publish(@RequestBody NewsManageVo newsManageVo){
        // 保存
        manageService.publish(newsManageVo);
        return ResponseVo.success();
    }
}
